package controller

import (
	"{{.ProjectName}}/internal/service"
	greeterPb "{{.ProjectName}}/pb"

	"gitee.com/wu-jin-feng/fgin"
	"github.com/gin-gonic/gin"
)

type GreeterController struct {
	F          *fgin.Fgin
	GreeterSvc *service.GreeterService
}

func (c *GreeterController) GetScheme(ctx *gin.Context) {
	type getSchemeInput struct {
		Path string `form:"path"`
		Info string `form:"info"`
		Name string `form:"name"`
	}
	input := getSchemeInput{}
	if err := fgin.FbindParams(ctx, &input); err != nil {
		fgin.ReturnJson(ctx, 400, nil, err)
		return
	}
	service := c.GreeterSvc
	serviceInput := greeterPb.GetSchemeReq{
		Path: input.Path,
		Info: &greeterPb.GetSchemeRespInfo{
			Info: input.Info,
			Name: input.Name,
		},
	}
	out, err := service.GetScheme(ctx, &serviceInput)
	if err != nil {
		fgin.ReturnJson(ctx, 400, nil, err)
		return
	}
	fgin.ReturnJson(ctx, 200, out, nil)
}
